using System;
using System.Web;
using System.Drawing.Design;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Drawing;
using System.Collections;
using System.Data;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Specialized;
using System.Security.Cryptography;
using ICSharpCode.SharpZipLib.GZip;


namespace ACM.cmsarea08.Controls
{
	[ToolboxData("<{0}:Itan_ifViewBlock runat=server Name=''></{0}:Itan_ifViewBlock>")]
	public class Itan_ifViewBlock : WebControl
    {
    	
        private string _nome;
        private string _html;
		
        
        [Bindable(true),
		 Browsable (true),
         Category("Appearance"),
         Description("Get/Set ViewBlock Name"),
         DefaultValue("")]
		public string Name
        {
            get
            {
                return _nome;
            }
            set
            {
                _nome = value;
            }
        }

        [Bindable(true),
		 Browsable (true),
         Category("Appearance"),
         Description("Get/Set ViewBlock Code"),
         DefaultValue(""),
         PersistenceMode(PersistenceMode.InnerProperty)]
		public string Block
        {
            get
            {
                return _html;
            }
            set
            {
                _html = value;
            }
        }
		
      
        public Itan_ifViewBlock() : base()   {
        	//inizializzatore Classe
        	_nome = "";
         }
 			
		override protected void OnInit(EventArgs e)
		{
			//HttpContext.Current.Response.Write("nome: " + Name);
			LoadBlock();
			InitializeComponent();
			base.OnInit(e);		
		}

		private void LoadBlock() {
			if(Name.Trim()=="")
				return;
			ACM.cmsarea08.Function.TextClass tcl = new ACM.cmsarea08.Function.TextClass();
			string basePT = ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle;
            string CurrentLanguage = "";
            if (this.Page is ACM.cmsarea08.Core.MainPage)
            {
                CurrentLanguage = ((ACM.cmsarea08.Core.MainPage)this.Page).Page_Lang;
            }
            else
            {
                if (ACM.cmsarea08.Users.CurrentUser != null)
                {
                    if (ACM.cmsarea08.Users.CurrentUser.Autorizzato && ACM.cmsarea08.Users.CurrentUser.PrefLanguage != "")
                        CurrentLanguage = ACM.cmsarea08.Users.CurrentUser.PrefLanguage;
                    else
                        CurrentLanguage = ACM.cmsarea08.mainconfiguration.MainConf.LinguaPredefinita;
                }
                else
                {
                    CurrentLanguage = ACM.cmsarea08.mainconfiguration.MainConf.LinguaPredefinita;
                }
            }

			object valid = ACM.cmsarea08.DBManager.mainConnection.HStandard_SC(
				" SELECT count(*) FROM "+basePT+"moduli where " + 
				" blocco_visivo = " +
				" (select id from "+basePT+"blocco_visivo where titolo='"+tcl.SqlTesto(Name.Trim())+"' limit 1)" +
                " and enabled ='1' and locate('" + CurrentLanguage + "',if(languages='','" + CurrentLanguage + "',languages))>0 ;");
			if(valid==null)
				return;
			if(valid.ToString()=="0")
				return;
			else {
				/* verifica se il modulo con nome ha figli. */
				Control aspControls = Page.ParseControl(this.Block);
				this.Controls.Add(aspControls);
				/* fine verifica. */
			}
		}
		
		private void InitializeComponent()
		{
			
			//this.Load += new System.EventHandler(this.Page_Load);
			
		}
		
   }
    

}
